Imports System.Data.OracleClient

Public Class clsMainclass

  Public mCmdMainClass As OracleCommand
  Public mDrMainClass As OracleDataReader

  Public mIntMainClassId As Integer
  Public mStrMainClassName As String
  Public mStrMainClassScope As String
  Public mStrMainClassCatg As String

  Public Function SelectMclsNameBasdIdxx() As Boolean

    Dim lStrQuery As String = String.Empty

    If mIntMainClassId <> 0 Then
      lStrQuery = lStrQuery & "select MCLS_IDXX,MCLS_NAME,MCLS_SCOP,MCLS_CATG from TRDX_MAIN_CLASS"
      lStrQuery = lStrQuery & " where MCLS_IDXX = " & mIntMainClassId

      mCmdMainClass = New OracleCommand(lStrQuery, con)
      mDrMainClass = mCmdMainClass.ExecuteReader

      SelectMclsNameBasdIdxx = True
    Else
      MessageBox.Show("Invalid Main Class Id", gCONST_MSG_HEADER, MessageBoxButtons.OK)
      SelectMclsNameBasdIdxx = False
    End If
  End Function






  Public Function SelectMclsBasdName() As Integer

    If Trim(mStrMainClassName) <> String.Empty Then

      mCmdMainClass = New OracleCommand("select count(*) from TRDX_MAIN_CLASS where MCLS_NAME = '" & mStrMainClassName & "'", con)
      Dim nCount As Integer = mCmdMainClass.ExecuteScalar()
      If nCount = 0 Then
        Return 0
      Else
        Return 1
      End If
    Else
      MessageBox.Show("Invalid Main Class Name", gCONST_MSG_HEADER, MessageBoxButtons.OK)
      Return 2
    End If

  End Function






  Public Function fnInsertMcls() As Integer

    Dim lIntSeqNum As Integer
    Dim lStrQuery As String = String.Empty

    If mStrMainClassName <> Nothing Then

      mCmdMainClass = New OracleCommand("select count(*) as CNT from TRDX_MAIN_CLASS", con)

      Dim nCount As Integer = mCmdMainClass.ExecuteScalar()

      If nCount = 0 Then
        lIntSeqNum = 0
      Else

        mCmdMainClass = New OracleCommand("select max(MCLS_IDXX) as CNT from TRDX_MAIN_CLASS", con)
        lIntSeqNum = mCmdMainClass.ExecuteScalar
      End If

      lStrQuery = lStrQuery & "insert into TRDX_MAIN_CLASS values(" _
                                & (lIntSeqNum + 1) & ",'" _
                                & mStrMainClassName & "','" _
                                & mStrMainClassScope & "','" _
                                & mStrMainClassCatg & "')"


      mCmdMainClass = New OracleCommand(lStrQuery, con)
      mCmdMainClass.ExecuteNonQuery()
      fnInsertMcls = lIntSeqNum + 1
    Else
      MessageBox.Show("Invalid values", gCONST_MSG_HEADER, MessageBoxButtons.OK)
      fnInsertMcls = -1
    End If

  End Function






  Public Function fnUpdateMcls() As Boolean

    Dim lStrQuery As String = String.Empty


    mCmdMainClass = New OracleCommand("select count(*) as CNT from TRDX_MAIN_CLASS where MCLS_IDXX = " _
                                    & mIntMainClassId, con)
    Dim ncount As Integer = mCmdMainClass.ExecuteScalar

    If ncount <> 0 And mStrMainClassName <> Nothing Then
      lStrQuery = "update TRDX_MAIN_CLASS set"
      lStrQuery = lStrQuery & " MCLS_NAME = '" & mStrMainClassName & "'"
      lStrQuery = lStrQuery & ",MCLS_SCOP = '" & mStrMainClassScope & "'"
      lStrQuery = lStrQuery & ",MCLS_CATG = '" & mStrMainClassCatg & "'"
      lStrQuery = lStrQuery & " where "
      lStrQuery = lStrQuery & "MCLS_IDXX = " & mIntMainClassId


      mCmdMainClass = New OracleCommand(lStrQuery, con)
      mCmdMainClass.ExecuteNonQuery()
      fnUpdateMcls = True
    Else
      MessageBox.Show("Invalid Values", gCONST_MSG_HEADER, MessageBoxButtons.OK)
      fnUpdateMcls = False
    End If

  End Function





  Public Function fnSelectAllMcls() As Boolean


    mCmdMainClass = New OracleCommand("select * from TRDX_MAIN_CLASS", con)
    mDrMainClass = mCmdMainClass.ExecuteReader

    fnSelectAllMcls = True

  End Function





  Public Function fnSelectMclsIdxxBasdName() As Integer

    If Trim(mStrMainClassName) <> String.Empty Then

      mCmdMainClass = New OracleCommand("select MCLS_IDXX from TRDX_MAIN_CLASS where MCLS_NAME = '" & mStrMainClassName + "'", con)

      mDrMainClass = mCmdMainClass.ExecuteReader

    Else

      MessageBox.Show("Invalid Main Class Name", gCONST_MSG_HEADER, MessageBoxButtons.OK)
      fnSelectMclsIdxxBasdName = False
    End If
  End Function

End Class